home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pnl003.zip / TOKEN.PAS < prev   
Pascal/Delphi Source File  |  1990-05-30  |  14KB  |  173 lines

  1. {************************************************************************       
  2. **                                                                              
  3. ** Token.pas  Advanced string handling procedures.                              
  4. **                                                                              
  5. ** Written by G.Hoogterp                                                        
  6. ** All Copyrights reserved                                                      
  7. ** Version 1.0                                                                  
  8. **                                                                              
  9. ** Use this unit as you like, you may modify it for personal use.               
  10. ** you may NOT distribute a modified version though!                            
  11. **                                                                              
  12. *************}                                                                  
  13. Unit Token;                                                                     
  14. Interface                                                                       
  15.                                                                                 
  16.                                                                                 
  17. {***********************************************************************        
  18. **                                                                              
  19. ** Findtoken splits a tokenlist into a head and a tail.                         
  20. **                                                                              
  21. **********}                                                                     
  22.                                                                                 
  23. Function FindToken(Var TokenList : String;Delimiters : String):String;          
  24.                                                                                 
  25. {***********************************************************************        
  26. **                                                                              
  27. ** SimplifyDelimiter simplifies the delimiters in a tokenlist.                  
  28. **                                                                              
  29. **********}                                                                     
  30.                                                                                 
  31. Procedure SimplifyDelimiters(Var TokenList : String;Delimiters : String);       
  32.                                                                                 
  33. {***********************************************************************        
  34. **                                                                              
  35. ** SkipLeadingSpaces deletes the leading spaces of a tokenlist                  
  36. **                                                                              
  37. **********}                                                                     
  38.                                                                                 
  39. Procedure SkipLeadingSpaces(Var TokenList : String);                            
  40.                                                                                 
  41. {***********************************************************************        
  42. **                                                                              
  43. ** DeletetrailingSpaces deletes the trailing spaces of a tokenlist              
  44. **                                                                              
  45. **********}                                                                     
  46.                                                                                 
  47. Procedure DeleteTrailingSpaces(Var TokenList : String);                         
  48.                                                                                 
  49. {***********************************************************************        
  50. **                                                                              
  51. ** UpStr converts a tokenlist to all uppercase                                  
  52. ** DownStr converts a tokenlist to all lowercase                                
  53. **                                                                              
  54. **********}                                                                     
  55.                                                                                 
  56. Procedure UpStr(Var TokenList : String);                                        
  57. Procedure DownStr(Var TokenList : String);                                      
  58.                                                                                 
  59. {***********************************************************************        
  60. **                                                                              
  61. ** Delete noise deletes all charactes you don't want to find in a tokenlist.    
  62. **                                                                              
  63. **********}                                                                     
  64.                                                                                 
  65. Procedure DeleteNoise(Var TokenList : String;Noise : String);                   
  66.                                                                                 
  67. {***********************************************************************        
  68. **                                                                              
  69. ** Replace token can be used to change multiletter delimiters into              
  70. ** single letter delimiters. (Or an other multiletter delimiter)                
  71. **                                                                              
  72. **********}                                                                     
  73.                                                                                 
  74. Procedure ReplaceToken(Var TokenList : String;Tok1,Tok2 : String);              
  75.                                                                                 
  76.                                                                                 
  77. Implementation                                                                  
  78.                                                                                 
  79. Function FindToken(Var TokenList : String;Delimiters : String):String;          
  80. Var HStr : String;                                                              
  81.     Tel  : Byte;                                                                
  82. Begin                                                                           
  83. HStr:='';                                                                       
  84. Tel:=1;                                                                         
  85. While (Tel<=Length(TokenList)) And                                              
  86.       (Pos(UpCase(TokenList[Tel]),Delimiters)=0) Do                             
  87.  HStr:=HStr+TokenList[Tel];                                                     
  88.  Inc(Tel);                                                                      
  89.  End;                                                                           
  90. FindToken:=HStr;                                                                
  91. Delete(TokenList,1,Tel);                                                        
  92. End;                                                                            
  93.                                                                                 
  94. Procedure SimplifyDelimiters(Var TokenList : String;Delimiters : String);       
  95. Var DelTel  : Byte;                                                             
  96. Begin                                                                           
  97. DelTel:=1;                                                                      
  98. Repeat                                                                          
  99. If (Pos(TokenList[DelTel],Delimiters)>0) And                                    
  100.    (Pos(TokenList[DelTel+1],Delimiters)>0)                                      
  101.    Then Delete(TokenList,DelTel,1)                                              
  102.    Else Inc(DelTel);                                                            
  103. Until DelTel>=(Length(TokenList)-1);                                            
  104. End;                                                                            
  105.                                                                                 
  106. Procedure SkipLeadingSpaces(Var TokenList : String);                            
  107. Var Tel : Byte;                                                                 
  108. Begin                                                                           
  109. Tel:=1;                                                                         
  110. While (Tel<=Length(TokenList)) And (TokenList[Tel]=' ') Do                      
  111.  Inc(Tel);                                                                      
  112. Delete(TokenList,1,Tel-1);                                                      
  113. End;                                                                            
  114.                                                                                 
  115. Procedure DeleteTrailingSpaces(Var TokenList : String);                         
  116. Var Tel : Byte;                                                                 
  117. Begin                                                                           
  118. Tel:=Length(TokenList);                                                         
  119. While (Tel>0) And (TokenList[Tel]=' ') Do                                       
  120.  Dec(Tel);                                                                      
  121. TokenList[0]:=Chr(Tel);                                                         
  122. End;                                                                            
  123.                                                                                 
  124. Procedure DeleteNoise(Var TokenList : String;Noise : String);                   
  125. Var NoiseTel : Byte;                                                            
  126.     PosNoise : Byte;                                                            
  127. Begin                                                                           
  128. For NoiseTel:=1 To Length(Noise) Do                                             
  129.  Begin                                                                          
  130.  Repeat                                                                         
  131.   PosNoise:=Pos(Noise[NoiseTel],TokenList);                                     
  132.   If PosNoise>0                                                                 
  133.      Then Delete(TokenList,PosNoise,1);                                         
  134.  Until PosNoise=0;                                                              
  135.  End;                                                                           
  136. End;                                                                            
  137.                                                                                 
  138. Procedure ReplaceToken(Var TokenList : String;Tok1,Tok2 : String);              
  139. Var Tok1Pos : Byte;                                                             
  140.     HStr    : String;                                                           
  141. Begin                                                                           
  142. HStr:=TokenList;                                                                
  143. UpStr(HStr);                                                                    
  144. UpStr(Tok1);                                                                    
  145. Repeat                                                                          
  146.  Tok1Pos:=Pos(Tok1,HStr);                                                       
  147.  If Tok1Pos>0                                                                   
  148.     Then Begin                                                                  
  149.          Delete(TokenList,Tok1Pos,Length(Tok1));                                
  150.          Insert(Tok2,TokenList,Tok1Pos);                                        
  151.          HStr:=TokenList;                                                       
  152.          UpStr(HStr);                                                           
  153.          End;                                                                   
  154. Until Tok1Pos=0;                                                                
  155. End;                                                                            
  156.                                                                                 
  157. Procedure UpStr(Var TokenList : String);                                        
  158. Var Tel : Byte;                                                                 
  159. Begin                                                                           
  160. For Tel:=1 to Length(TokenList) Do                                              
  161.  TokenList[Tel]:=UpCase(TokenList[Tel]);                                        
  162. End;                                                                            
  163.                                                                                 
  164. Procedure DownStr(Var TokenList : String);                                      
  165. Var Tel : Byte;                                                                 
  166. Begin                                                                           
  167. For Tel:=1 to Length(TokenList) Do                                              
  168.  If TokenList[Tel] in ['a'..'z']                                                
  169.     Then TokenList[Tel]:=Chr(Byte(TokenList[Tel])+32);                          
  170. End;                                                                            
  171.                                                                                 
  172. End.                                                                            
  173.